using System;
using System.Collections.Generic;
using System.Text;
using PH.Common;

namespace Hoshimi
{
    public class AIBot_BuildState : State
	{
		#region Singleton

		// Fields
		protected static AIBot_BuildState instance;

		// Constructor
		protected AIBot_BuildState() : base() { }

		// Methods
		public static AIBot_BuildState Instance()
		{
			// Uses "Lazy initialization"
			if( instance == null ) 
				instance = new AIBot_BuildState();

			return instance;
		}

		#endregion

		#region Methods
		
		public override bool Play( Unit unit )
		{
			AIBot bot = (AIBot) unit;

            bot.SetName("Build");

            // We can't give orders to the bot. We stop
			if ( bot.State != NanoBotState.WaitingOrders && bot.State != NanoBotState.Moving ) 
			{
				return true;
			}

			if (bot.BuildWallOrBlockerIfInteresting())
			{
				return true;
			}

			if (bot.IsFastBuildNeedleModeOn())
			{
				unit.myStateMachine.ChangeState( AIBot_RestState.Instance() );
                return false;
			}

			// We build all units in stack
            if (!bot.BuildBot())
            {
                unit.myStateMachine.ChangeState( AIBot_RestState.Instance() );
                return false;
            }

            return true;
		}

		#endregion
	}
}
